home *** CD-ROM | disk | FTP | other *** search
- Path: snail.stack.urc.tue.nl!not-for-mail
- From: pascalz@stack.urc.tue.nl (Pascal Zinken)
- Newsgroups: comp.lang.c
- Subject: How to expand printf()?
- Date: 22 Mar 1996 01:27:28 +0100
- Organization: MCGV Stack, Eindhoven University of Technology, the Netherlands.
- Message-ID: <4iss5g$2av@snail.stack.urc.tue.nl>
- NNTP-Posting-Host: snail.stack.urc.tue.nl
- X-Newsreader: TIN [version 1.2 PL2]
-
- Well... As the subject said... I am currently seeking a nice (and as
- portable as possible) way to expand the function printf(). I want to
- insert some new tokens, namely something like %C for changing the color
- of the text.
-
- This could be done by 'simply' writing my own printf(). But i really don't
- feel like that.
-
- Then i got to the part i thought of the following, though i am not sure if
- it would work because i do not yet fully understand the way stdarg works.
- I would examine the format string:
-
- char *pcFormat; /* Given as parameter. */
- if ( IsNormalFormatSpecifier( &pcFormat[ nCurrentPosition]))
- vprintf( pcBuffer, &pcFormat[ nCurrentPosition], pArg);
- else
- UseOwnRoutineToFillpcBuffer();
-
- pArg is then a va_list variable. But, then, i am not sure if calling
- vprintf() a multiple number of times will do exactly what i want.
-
- For example, if i had the following string...
-
- "printing %d characters in %Ccolor resulted in %d", with the additional
- parameters 200, WHITE (or something like that) and 42, would
- calling vprintf(), OwnRoutine, vprintf() in that order do the trick?
-
- Please... i've had my time reading the FAQ-list, examined a number of books
- on handling a variable parameter count, but did not yet find out the answer.
-
- Oh, before i forget, i do know how to handle a variable number of arguments.
- I only do not know how to expand printf() without rewriting it from scratch.
- I just want the original printf() to handle the normal formats, and my own
- routine to handle my ones.
-
- Please... help me out..
- Send any usefull replies to either balls@cpc.nl or to
- pascalz@stack.urc.tue.nl
-
- though the latter one goes down too often on my account!
-
- Greetings, and thanx, Pascal Zinken
-